<?php
/**
 * 详情管理
 * ============================================================================

 * ============================================================================
 */
defined('BY_JYA') or exit('error');
$op=$_RQ['op']?$_RQ['op']:'detail';
cfc('core')->checklogin('jy_jdpm/member.index/');
$return['ntime']=TIMESTAMP;
$nickname=pdo_getcolumn('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['uid']),'nickname');
$return['nickname']=$nickname;		
$OrderStatus=$this->ordertypes();
if($op=='detail'){
	$pid = intval($_RQ['id']);
	$_SESSION['pid']=$pid;
	$set=$this->plugin_setting('basic');
	//分享送积分
	if($_RQ['fromuser'] && $_RQ['fromuser']!=$_SESSION['uid']){
		$set=$this->plugin_setting('basic');
		$add=$set['share'];
		if($add){
		$time = strtotime(date('Ymd'));
		$l1=pdo_count('jy_jdpm_credit_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_RQ['fromuser'],'createtime >'=>$time,'type'=>5));
		$l2=pdo_get('jy_jdpm_credit_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_RQ['fromuser'],'createtime >'=>$time,'pid'=>$pid,'type'=>5));
		$max=$set['sharemax']?$set['sharemax']:3;
		if($l1<$max && !$l2){
			pdo_insert('jy_jdpm_credit_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['fromuser'],'pid'=>$pid,'type'=>5,'is_add'=>1,'fee'=>$add,'remark'=>'分享拍品送积分','createtime'=>time()));
		}
		}
	}
	$orderset=$this->plugin_setting('order');
	$orderset['onsetbi']=$orderset['onsetbi']?:3;
	$setting=$this->plugin_setting('setting');
	$auctionset=$this->plugin_setting('auction');
	$setting['hdps']=json_decode($setting['hdps'],true);
	$setting['footernav']=json_decode($setting['footernav'],true);
	$return['channel'] = pdo_getall('jy_jdpm_goods_group',array('uniacid'=>$_SESSION['uniacid'],'pid' => 0),'','','paixu asc');
	$where = array('id'=>$pid);
	pdo_update('jy_jdpm_auction', array('click +='=>1), $where);
	/** 商品信息 **/
	$info = pdo_get('jy_jdpm_auction',$where);
	if($info['endstatus']==4){
		exi('拍品已撤拍!','error','goodslist/');
	}
	$info['memberinfo'] = get_member($info['mid']);
	$info['goodinfo'] = get_goodsinfo($info['goodsid']);
	$info['goodinfo']['images'] =json_decode($info['goodinfo']['images'],true);
	$info['goodinfo']['content'] = $info['goodinfo']['content'] ? $info['goodinfo']['content']:'<p>暂无详情内容</p>';
	$info['order'] = get_order($info['order_id']);

        /** 关注提醒 **/
        $AT         = pdo_get('jy_jdpm_scheduled',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid' => $pid));
        $RE         = pdo_get('jy_jdpm_attention',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid' => $pid));
		$return['ustx'] = $AT ? 1 : 0;
        $return['usgz'] = $RE ? 1 : 0;

        $ATnum = pdo_count('jy_jdpm_scheduled',array('uniacid'=>$_SESSION['uniacid'],'pid' => $pid),'mid');
		 $return['ATnum'] =$ATnum;
		$REnum = pdo_count('jy_jdpm_attention',array('uniacid'=>$_SESSION['uniacid'],'pid' => $pid),'mid');
		 $return['REnum'] =$REnum;


        /** 点击 **/
        $ack1 = pdo_getcolumn('jy_jdpm_auction',array('uniacid'=>$_SESSION['uniacid'],'id' => $pid),'clcount');
		$ack2 = pdo_getcolumn('jy_jdpm_auction',array('uniacid'=>$_SESSION['uniacid'],'id' => $pid),'click');

        /** 判断状态 0:未开拍;1:在拍;2:结束 **/
        $time               = time();
        $info['status_ing'] = $time > $info['starttime'] ? ($time > $info['endtime'] ? 2 : 1) : 0;

        /** 是否拍中 **/
        $info['is_success'] = $info['mid'] == $_SESSION['uid'] ? 1 : 0;

        /** 竞拍人数 */
        $info['auctionNum'] = pdo_count('jy_jdpm_freezelog',array('uniacid'=>$_SESSION['uniacid'],'pid' => $pid),'mid');

        /** 热门拍卖 **/
		$orderby='';
		$pindex = max(1, intval($_RQ['page']));
		$psize = 10;
		$total='';
		$hot = pdo_getslice('jy_jdpm_auction',array('uniacid'=>$_SESSION['uniacid'],'ishot'=>1,'endtime >'=>time(),'starttime <'=>time(),'endstatus <'=>4),array($pindex,$psize),$total,'','','clcount DESC');
		foreach ($hot AS $key => $val) {
            $goodinfo = pdo_get('jy_jdpm_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$val['goodsid']));
			$goodinfo['images'] = explode("|", $goodinfo['images']);
            $hot[$key]['images'] = $goodinfo['images'][0];
			$hot[$key]['title'] = $goodinfo['title'];
			$hot[$key]['content'] = $goodinfo['content'];
			$hot[$key]['ing'] = pdo_count('jy_jdpm_freezelog',array('uniacid'=>$_SESSION['uniacid'],'pid' => $val['pid']),'mid');;
        }
		$return['hot']=$hot?$hot:array();
		$totalpage=ceil($total/$psize);
		$totalpage=intval($totalpage);
		$return['totalpage'] =$totalpage;
		$return['params']['page'] =$pindex;

        /** 兑拍记录 **/
        $RecordList = pdo_getall('jy_jdpm_auction_record',array('uniacid'=>$_SESSION['uniacid'],'pid' => $pid),array('mid','createtime','money'),'','money DESC');
        foreach ($RecordList AS $Key => $value) {
			$member = get_member($value['mid']);
			$RecordList[$Key]['nickname'] = $member['nickname'];
            if (strpos($member['username'] , 'on_') !== false) {
                $string                      = substr($member['username'] , 3);
                $RecordList[$Key]['username'] = substr($string , 0,3) . '****' . substr($string , -4);
            } else {
                $RecordList[$Key]['username'] = substr($member['username'] ,0, 3) . '****' . substr($member['username'] , -4);
            }
            $RecordList[$Key]['ingname'] = substr($value['mid'] ,0, 1) . '******' . substr($value['mid'] , -1);
			$RecordList[$Key]['createtime'] = date('Y/m/d H:i:s',$value['createtime']);
        }
		$return['RecordList'] =$RecordList;
		$info['starttime2'] = date('Y/m/d H:i:s',$info['starttime']);
		$info['endtime2'] = date('Y/m/d H:i:s',$info['endtime']);
		$info['OrderStatus'] = $OrderStatus[$info['order']['status']];
        /** 判断当前价是否为起拍价的三倍或以上 **/
        $margin = ($info['nowprice'] > $info['onset'] * $orderset['onsetbi']) ? 1 : 0;
		$return['margin'] =$margin;
		$return['mid'] =$_SESSION['uid']?$_SESSION['uid']:0;
		$return['info'] =$info;

        /*** 添加足迹 ***/
        addFootMark($_SESSION['uid'],$pid);

        /**卖家承诺**/
        $promise = pdo_get('core_account_article',array('uniacid'=>$_SESSION['uniacid'],'id' => $set['promiseid']),'content');
        $return['promise'] =$promise;
        /**竞拍须知**/
        $notice = pdo_get('core_account_article',array('uniacid'=>$_SESSION['uniacid'],'id' => $set['xuzhiid']),'content');
		$return['notice'] =$notice;
		$info['stepsize']=$info['stepsize']?$info['stepsize']:10;
		if($info['stepsize_type']==1){
			$return['stepsizefee']=$info['onset'] +  $info['stepsize'];
		}else{
			$return['stepsizefee']=$info['onset']*$info['stepsize']/100;
		}
		$return['bidding']=$info['mid']>0 ?($info['nowprice']+$return['stepsizefee']):$info['onset'];
		$return['clinch']=$info['mid']>0?$info['nowprice']:$info['onset'];
		$jiafee=$info['nowprice']+$return['stepsizefee'];
		$onsetbifee=$info['onset']*$orderset['onsetbi'];
		$newpledge=$info['pledge']?100/$info['pledge']:2;
		$bzprice=$onsetbifee>0 && $jiafee>=$onsetbifee?$onsetbifee/$newpledge:$jiafee/$newpledge;
		$return['bzprice']=$info['mid']>0?$bzprice:$info['onset']/$newpledge;
		$return['ingname']=substr($info['mid'] ,0, 1) . '******' . substr($info['mid'] , -1);
		$return['post'] =array('pid'=>$pid);
		$return['sharedata'] =array(
			'title'=>$info['pname'],
			'desc'=>$info['pname'].'-'.$_SESSION['account']['title'],
			'link'=>custom_url('jy_jdpm/detail//pid='.$pid),
			'imgUrl'=>ATTACHMENT_URL.$info['goodinfo']['images'][0],
		);
		set_html('title',$info['pname']);
		exi($return);
}
if($op=='tx'){
	cfc('core')->checklogin('jy_jdpm/member.index/');
	$post=get_postdata();
	$pid = intval($post['id']);
	$info = pdo_get('jy_jdpm_auction',array('uniacid'=>$_SESSION['uniacid'],'id'=>$pid));
	$time               = time();
    $info['status_ing'] = $time > $info['starttime'] ? ($time > $info['endtime'] ? 2 : 1) : 0;
	if($info['status_ing']==1){
		$stype='ing';
	}
	if($info['status_ing']==0){
		$stype='fut';
	}
	if($info['status_ing']==2){
		exi('拍卖已结束','error');
	}
	$AT         = pdo_get('jy_jdpm_scheduled',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid' => $pid));
	if(!$AT){
		pdo_insert('jy_jdpm_scheduled',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid' => $pid,'createtime'=>time(),'stype'=>$stype));
		exi('设置成功');
	}else{
		pdo_delete('jy_jdpm_scheduled',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid' => $pid));
		exi('取消成功');
	}
	 
       
}
if($op=='gz'){
	cfc('core')->checklogin('jy_jdpm/member.index/');
	$post=get_postdata();
	$pid = intval($post['pid']);
	$info = pdo_get('jy_jdpm_attention',array('uniacid'=>$_SESSION['uniacid'],'pid'=>$pid));
	
	 $RE   = pdo_get('jy_jdpm_attention',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid' => $pid));
	if(!$RE){
		pdo_insert('jy_jdpm_attention',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid' => $pid,'rela'=>'p-u'));
		exi('关注成功');
	}else{
		pdo_delete('jy_jdpm_attention',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid' => $pid));
		exi('取消成功');
	}
	
}
?>